class Solution {
    public int findSubstringInWraproundString(String s) {
        int len = s.length() ;
        int[] dp = new int[len+1] ;
        int[] hash = new int[26] ;
        s = " " +s ;
        for(int i = 1 ; i <= len ;  i ++){
             dp[i] = 1 ;
             char a = s.charAt(i) , b = s.charAt(i-1) ;
             if(a-b==1 || a=='a' && b == 'z'){
                dp[i] += dp[i-1] ;
             }
             hash[a-'a'] = Math.max(hash[a-'a'] , dp[i]);
        }
        int sum = 0 ;
        for(int num : hash){
            sum += num;
        }
      return sum ;
    }
}